﻿#ifndef _SHELL_MESSAGE_H_
#define _SHELL_MESSAGE_H_

#include "ByteBuf.h"
#include <string>
#include "cocos2d.h"

using namespace cocos2d;

class Bean
{
public:
	virtual bool read_from(ByteBuf& buf) = 0;
	virtual bool write_to(ByteBuf& buf) = 0;

	// int8
	int8 readInt8(ByteBuf& buf);
	void writeInt8(ByteBuf& buf, int8 value);

	//short
	short readShort(ByteBuf& buf);
	void writeShort(ByteBuf& buf, short value);

	// int16
	int16 readInt16(ByteBuf& buf);
	void writeInt16(ByteBuf& buf, int16 value);
	// int32
	int32 readInt32(ByteBuf& buf);
	void writeInt32(ByteBuf& buf, int32 value);
	// int64
	int64 readInt64(ByteBuf& buf);
	void writeInt64(ByteBuf& buf, int64 value);
	// string
	std::string& readString(ByteBuf& buf, std::string& value);
	void writeString(ByteBuf& buf, std::string& value);
	// bean
	Bean& readBean(ByteBuf& buf, Bean& value);
	void writeBean(ByteBuf& buf, Bean& value);
};

class Message : public Bean
{
public:
	Message();
	virtual ~Message();
	virtual int getId() = 0;
	virtual __String* getData(){ return NULL; }
	virtual void reset();
};



#endif
